//
//  Status.swift
//  Weibo
//
//  Created by gdarkness on 16/3/20.
//  Copyright © 2016年 gdarkness. All rights reserved.
//

import UIKit

class Status: NSObject {
    // 行高
    var height: CGFloat?
    //微博创建时间
    var created_at: String?
    //微博内容
    var text: String?
    //微博来源
    var source: String?
    //微博配图
    var pic_urls: [[String: AnyObject]]?
    //转发
    var reposts_count: Int = 0
    //评论数
    var comments_count: Int = 0
    //表态数
    var attitudes_count: Int = 0
    //微博ID
    var id : Int64 = 0
    //微博配图，存放图片的url
    var storePictureURLs : [NSURL]?
    //用户模型
    var user:User?
    //被转发的微博
    var retweeted_status:Status?
    //字典转模型
    init(dict: [String : AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    override func setValue(value: AnyObject?, forUndefinedKey keyPath: String) {}
    //打印
    override var description: String{
        let keys = ["created_at","id","text","source","pic_urls","reposts_count","comments_count","attitudes_count","user"]
        // \n换行
        // \t : 制表符 = table键
        return "\n\t微博模型: \(dictionaryWithValuesForKeys(keys).description)"
        
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        //判断key == user 时，将value字典转成模型，并复制给user属性
        if key == "user"{
            if let dict = value as? [String :AnyObject]{
                //value 是一个字典，字典转模型
                user  = User(dict: dict)
            }
            //要return ，不要走父类的将字典赋值给user属性
            return
        }else if key == "retweeted_status"{
            if let dict = value as? [String :AnyObject]{
                //字典转模型
                retweeted_status = Status(dict: dict)
            }
            //要return 不要走父类的字典赋值给retweeted_status属性
            return
        }
        super.setValue(value, forKey: key)
    }

}
    
    
    //代表情图片的属性文本
    //var attrText :NSAttributedString?
    //微博来源
//    var source :String?{
//        didSet{
//            //在didSet 里面再次 给自己赋值，是不会再次调用didSet
//            source = source?.sinaSource()
//        }
//    }
    //微博配图:数组里面放的是字典
//    var pic_urls:[[String : AnyObject]]?{
//        didSet{
//            let count = pic_urls?.count ?? 0
//            if count == 0{
//                return
//            }
//            //创建数组，来保存图片的地址
//            storePictureURLs = [NSURL]()
//            for dict in pic_urls!{
//                let urlString = dict["thumbnail_pic"] as! String
//                let url = NSURL (string: urlString)
//                storePictureURLs?.append(url!)
//            }
//        }
//    }

    


